package wqh.global;


//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.stereotype.Service;
//import wqh.domain.User;
//import wqh.service.UserService;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

//@Service("sessionService")
public class SessionListener implements HttpSessionListener{

//    @Autowired
//    private UserService userService;

    public void sessionCreated(HttpSessionEvent se)
    {

    }

    public void sessionDestroyed(HttpSessionEvent se)
    {
        String user = GlobalSession.removeSessionBySessionIDGetName(se.getSession().getId());
        System.out.println("用户超时下线：" + user +":" + se.getSession().getId());
//        用户是否在线应该存在MYSQL里，一下方法没法实现，若一定要存数据库，则应该用spring security 和 spring session
//        if(user != null)
//        {
//            User userObj = new User();
//            userObj.setUser(user);
//            User findUser = userService.findAllByObject(userObj).get(0);
//            findUser.setOnline((byte)0);
//            System.out.println(findUser.toString());
//            userService.updateDataById(findUser);
//        }
    }
}
